const SMSClient = require('@alicloud/sms-sdk')
const _sms = module.exports

// 创建短信验证码
_sms.send = async (mobile, clientInfo) => {
    if (!_.trim(mobile)) throw new Error('手机号不能为空')
    if (!helper.isCellPhone(mobile)) throw new Error('手机号格式不正确')
    if (!clientInfo.sign_name) throw new Error('短信签名不能为空')
    if (!clientInfo.template_code) throw new Error('短信模板不能为空')
    // 发送短信
    let templateParam = JSON.stringify(clientInfo.content)

    let smsClient = new SMSClient({
        accessKeyId: clientInfo.app_key,
        secretAccessKey: clientInfo.app_secret
    })

    const sendSMSResult = await smsClient.sendSMS({
        PhoneNumbers: mobile,
        SignName: clientInfo.sign_name,
        TemplateCode: clientInfo.template_code,
        TemplateParam: templateParam
    })

    log4js.debug('_sms.send ======', sendSMSResult)

    return sendSMSResult
}



